<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 用户输入内容 -->
        <input type="text" @keydown.enter="inputHandle" :value="inputValue">

        <!-- 未完成 -->
        <h1>未完成事件</h1>
        <div class="not-finished">
            <div v-for="(item,index) in notFinishedArr" :key="item.id">
                <input type="checkbox" :checked="item.isChecked" @change="changeHandle(item,index)" >
                <span>{{item.thing}}</span>
                <button @click="notFinishedArr.splice(index,1)">删除</button>
            </div>
        </div>

        <!-- 已经完成 -->
        <h1>已经完成事件</h1>
        <div class="finished">
            <div v-for="(item,index) in finishedArr" :key="item.id">
                <input type="checkbox" :checked="item.isChecked" @change="changeHandle(item,index)">
                <span>{{item.thing}}</span>
                <button @click="finishedArr.splice(index,1)">删除</button>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        let vm = new Vue({
            el: "#app",
            data: {
                // 初始值(响应值)
                inputValue:"",
                // 未完成的事情
                notFinishedArr: [{
                    id: 1,
                    thing: "敲代码",
                    isChecked: false
                }, {
                    id: 2,
                    thing: "整理笔记",
                    isChecked: false
                }],
                //  已完成的事情
                finishedArr: [{
                    id: 3,
                    thing: "脑袋放空, 进入提前放假模式",
                    isChecked: true
                }]
            },
            methods: {
                // input框输入内容处理函数
                inputHandle($event){
                    // console.log($event.target.value);
                    // 将input的值赋给响应值
                    this.inputValue=$event.target.value;
                    // 添加到未完成事件的数组中
                    this.notFinishedArr.push({
                        id:Date.now(),
                        thing:this.inputValue,
                        isChecked:false
                    });
                    // 清空input框的值
                    this.inputValue="";
                },
                changeHandle(item,index){
                    item.isChecked=!item.isChecked;
                    // 如果isChecked为true，就意味着已完成
                    if(item.isChecked){
                        // 推进已完成的数组中
                        this.finishedArr.push(item);
                        // 删除当前在位完成的数组对应成员 
                        this.notFinishedArr.splice(index,1);
                    }else{
                        // 推进未完成的数组中
                        this.notFinishedArr.push(item);
                        this.finishedArr.splice(index,1)
                    }
                }
            }
        })
    </script>
</body>

</html>